package com.yidu.InventoryManagement.mapper;

import com.yidu.InventoryManagement.entity.TAStock;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * @author 梁俊
 * @date 2022/12/9
 * &@version 1.0
 */
@Mapper
public interface TAStockMapper {
    /**
     * 分页模糊查ta库存
     * @param map
     * @return
     */
    @Select("SELECT * FROM TAStock WHERE  DATE LIKE #{date} LIMIT #{page},#{limit}")
    public List<TAStock> selectTAStockk(Map map);


    /**
     * 查询TA库存id是否为空
     * @return
     */
    @Select("SELECT count(*) FROM tastock")
    public int selectSecurityAccrualStockIdd();


    /**
     * 分页查行数
     * @param date
     * @return
     */
    @Select("SELECT COUNT(*) FROM TAStock WHERE  DATE LIKE #{date}")
    int selectTAStockCount(String date);

    /**
     * 批量删除
     * @return
     */
    public int deleteTaShockk(List securityAccrualStockId);

    /**
     * 添加
     * @param taStock ta库存对象
     * @return
     */
    @Insert("INSERT INTO  TAStock VALUES(#{securityAccrualStockId},#{date},#{initialState},#{quantity},#{money},#{remark},#{fundId},#{remarks})")
    public int insertTaShockk(TAStock taStock);


    /**
     * 查询ta库存id最大值
     * @return
     */
     @Select("SELECT securityAccrualStockId FROM TAStock ORDER BY securityAccrualStockId  DESC LIMIT 1")
     public String selectDaId();


    /**
     * TA库存修改
     * @param taStock
     * @return
     */
     @Update("update TAStock set DATE=#{date},initialState=#{initialState},quantity=#{quantity},money=#{money},remark=#{remark},fundId=#{fundId},remarks=#{remarks} where securityAccrualStockId=#{securityAccrualStockId}")
    public int updateTAStockk(TAStock taStock);


     /////////
    /**
     * 根据时间获取ta库存的总数量
     *
     * @param taStock ta库存对象
     * @return double ta库存总数量
     * @author 任俊杰
     */
    @Select("select sum(quantity) from TAStock where 1 = 1  and date = #{date} and fundId= #{fundId}")
    double getTaTotalQuantityByTime(TAStock taStock);

}

